var webdir='http://www.2admin.co.cc';
var limit=10;
var start=0;
var row=0;

var pageselect=1;
$(document).ready(function() {



}); 
function getUrlVars2() 
{
var vars = {};
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
vars[key] = value;
});
return vars;
}
function settable(myObject)
{
        for (variable in myObject.data)
             {   
              var obj = myObject.data[variable]; 
               if(obj.pic)
               {
                   var pic=obj.pic;
               }else
               {
                   var pic='meeting_user.jpg';
               }
               if(obj.createby==localStorage.getItem("uid"))
               {
                var classchat='odd';   
               }else
               {
               var classchat='even';       
               }
               var str='<li id="" class="comment parent '+classchat+'"><div class="comment-body" id=""><div class="comment-author"><img height="32" width="32" class="avatar" src="images/'+pic+'" alt="">        <span class="fn">'+obj.username+'</span> <span class="says">พูดว่า:</span><span class="comment-meta"><a href="#">'+obj.createdate+'</a></span></div><p>'+obj.msg+'</p></div></li>';

               $('#commentlist').append(str);  
         
             
             
  
            }
}
function getmsg()
{
   
    $.post(webdir+'/ajax.php',{functioncall:'getmsgbyuid',uid:localStorage.getItem("uid"),uid2:getUrlVars2()['uid']} ,function(data) {
    var view;
     var myObject = eval('(' + data + ')');
            
            
                     
            if(myObject.count>0)
            { 
            if(row==0)
            {$('#commentlist').html(''); 
                row=myObject.data.length;
                settable(myObject);
            }else
            {
              //  alert('row==>'+row+' lenth==>'+myObject.data.length);
                if(row==myObject.data.length)
                {
                    
                }else
                {
                     $('#commentlist').html(''); 
                     row=myObject.data.length
                     settable(myObject);

            
                }
            }
            
            }
         setTimeout("getmsg()",3000);
});
    
}
function setmsg()
{
        $.post(webdir+'/ajax.php',{functioncall:'setmsgbyuid',uid:localStorage.getItem("uid"),uid2:getUrlVars2()['uid'],msg:$('#commenttext').val()} ,function(data) {
    var view;
     var myObject = eval('(' + data + ')');
            
            $('#commentlist').html(''); 
            if(myObject.count>0)
            { 
            settable(myObject);
            }
     
});
}